﻿
Imports System.ComponentModel

Public Class AdderModel
    Public Text As String
    Public Sub New()
        inputCurrent1Value = New Current()
        inputCurrent2Value = New Current()
        outputCurrentValue = New Current()
        AddHandler InputCurrent1.PropertyChanged, AddressOf PropertyChangedHandler
        AddHandler InputCurrent2.PropertyChanged, AddressOf PropertyChangedHandler
    End Sub

    Private inputCurrent1Value As Current
    Public Property InputCurrent1 As Current
        Get
            Return inputCurrent1Value
        End Get
        Set(ByVal value As Current)
            inputCurrent1Value = value
            AddHandler InputCurrent1.PropertyChanged, AddressOf PropertyChangedHandler
            CalculateVoltage()
        End Set
    End Property

    Private inputCurrent2Value As Current
    Public Property InputCurrent2 As Current
        Get
            Return inputCurrent2Value
        End Get
        Set(ByVal value As Current)
            inputCurrent2Value = value
            AddHandler InputCurrent2.PropertyChanged, AddressOf PropertyChangedHandler
            CalculateVoltage()
        End Set
    End Property

    Private outputCurrentValue As Current
    Public ReadOnly Property OutputCurrent As Current
        Get
            Return outputCurrentValue
        End Get
    End Property

    Private Sub CalculateVoltage()
        outputCurrentValue.Voltage = inputCurrent1Value.Voltage + inputCurrent2Value.Voltage
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Output"))
    End Sub

    Private Sub PropertyChangedHandler(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        Select Case e.PropertyName
            Case "Voltage"
                CalculateVoltage()
        End Select
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
End Class
